//
//  main.m
//  Hiranipra.Game.Client
//
//  Created by Ben Vanik on 5/30/08.
//  Copyright __MyCompanyName__ 2008. All rights reserved.
//

#include "HiranipraCommon.h"
#include "ClientApp.h"
#include "CoreFoundation/CoreFoundation.h"

using namespace Hiranipra;
using namespace Hiranipra::Client;

ClientApp _clientApp;

int main(int argc, char *argv[])
{
	CFBundleRef bundle = CFBundleGetMainBundle();
	CFURLRef url = CFBundleCopyBundleURL( bundle );
	UInt8 urlBuffer[ 1024 ];
	CFURLGetFileSystemRepresentation( url, true, urlBuffer, 1024 );
	CFRelease( url );
	CFRelease( bundle );
	wstring appPath = wstring( WidenString( ( char* )urlBuffer ) );
	int slash = appPath.find_last_of( L"/" );
	if( slash <= 0 )
		slash = appPath.find_last_of( L"\\" );
	appPath = appPath.substr( 0, slash + 1 );
	
	vector<wstring> args;
	for( int n = 1; n < argc; n++ )
		args.push_back( wstring( WidenString( argv[ n ] ) ) );
	
	_clientApp.RegisterAssembly( L"Hiranipra.Platform.OpenGL.bundle" );
	_clientApp.RegisterAssembly( L"Hiranipra.Platform.PhysFS.bundle" );
	_clientApp.RegisterAssembly( L"Hiranipra.Platform.MacOSX.bundle" );
	
	return _clientApp.Start( appPath, args );
}
